<template>
    <el-dialog :visible.sync="modelValue" :title="'图片'" width="30%" height="550" append-to-body
        :modal-append-to-body="false" :close-on-click-modal="false" top="8vh" custom-class="casc-dialog">
        <div class="content">
            <UploadPhotos 
                :list="uploadConfig.list"
                 @update:list="updatePhotoList" 
                 :isUpload="isUpload" 
                 :limit="maxLimit"
                :disabled="delImg" 
            />
        </div>
        <template #footer>
            <div class="flex_between">
                <div></div>
                <div>
                    <el-button @click="close" size="mini"> 取 消 </el-button>
                    <el-button type="primary" @click="handleSubmit()" size="mini"> 确 定 </el-button>
                </div>
            </div>
        </template>
    </el-dialog>
</template>

<script setup>
import { ref, onMounted, defineExpose, defineProps, getCurrentInstance, defineEmits } from '@vue/composition-api'
import config from "@/js/conf/Config.js"
const { proxy } = getCurrentInstance()
import UploadPhotos from '@/components/commV2/UploadPhotos/index.vue'
const emit = defineEmits(['close'])
const modelValue = ref(false)

const props = defineProps({
    delImg: {
        type: Boolean,
        default: false
    },
    isUpload: {
        type: Boolean,
        default: true
    },
    maxLimit: {
        type: [Number, String],
        default: 10
    }
})
const close = () => {
    modelValue.value = false
}
const updatePhotoList = (newList) => {
    uploadConfig.value.list = [...newList]
}

const handleSubmit = () => {
    emit('update:photoList', uploadConfig.value)
    close()
}

// 上传文件，传过来的参数
const uploadConfig = ref({
    config: {},
    list: []
});
defineExpose({
    show: (data) => {
        uploadConfig.value = { ...data };
        modelValue.value = true
    },
    close
})

onMounted(() => { })

</script>

<style lang="scss">
.casc-dialog {
    .el-dialog__body {
        padding: 0px !important;
    }
}
</style>

<style scoped lang="scss">
.content {
    height: 500px;
    padding: 10px;
    overflow-y: auto;
    height: 450px;
}

.printer-form {
    width: 100%;
}

.full-width-input {
    width: 100%;
}

.widths-input {
    flex: 1;
    margin-right: 5px;
}

.flex_between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 优化多选下拉框的样式 */
:deep(.el-select) {
    .el-select__tags {
        flex-wrap: wrap;
    }

    .el-select__input {
        min-width: 60px;
    }
}
</style>